import http from '../../core/request'
import { Receipt } from './index.type'

// 获取收款方式列表
const getReceiptMethod = () => {
    return http.get<Receipt.Res.ReceiptMethod[]>('/payment/method', {}, { loading: false })
}

// 获取银行列表
const getBankNameList = () => {
    return http.get('/qxt/dict-data', { dictType: 'bank_code' }, { loading: false })
}

// 获取默认收款账号
const getDefaultReceiptAccount = () => {
    return http.get<Receipt.Res.CollectionInfo>('/payment-options/get-default-collect-way', {}, { loading: true })
}

// 获取个人收款列表
const getReceiptList = (params: Receipt.Params.Select) => {
    return http.get<Receipt.Res.Info>('/payment-options', params, { loading: true })
}

// 新增收款银行卡
const addBankCard = (params: Receipt.Params.AddOrUpdateContent) => {
    return http.post('/payment-options/bank-card', params, { loading: true })
}

// 新增收款微信/支付宝
const addWechatOrAlipay = (params: Receipt.Params.AddOrUpdateContent) => {
    return http.post('/payment-options/payment-method', params, { loading: true })
}

// 根据银行卡号获取银行名称
const getBankNameByCardNo = (params: Receipt.Params.BankInfo) => {
    return http.get('/payment-options/bank-name', params, { loading: false })
}

// 根据银行卡图片获取银行信息
const getBankInfoByCardImage = (params: Receipt.Params.BankInfo) => {
    return http.get<Receipt.Res.BankInfo>('/payment-options/get-Bank-information', params, { loading: false })
}

// 删除收款信息
const deleteReceipt = (params: Receipt.Params.Delete) => {
    return http.post('/payment-options/del-cards', params, { loading: true })
}

// 设置是否默认
const setIsDefault = (params: Receipt.Params.setDefault) => {
    return http.get('/payment-options/type-default', params, { loading: false })
}

// 获取详情信息
const getDetailInfo = (bankId: string) =>  {
    return http.get<Receipt.Res.CollectionInfo>('/payment-options/bank-card-detail', { bankId: bankId }, { loading: true })
}

// 修改银行卡信息
const updateBankCard = (params: Receipt.Params.AddOrUpdateContent) => {
    return http.post('/payment-options/bank-card/update', params, { loading: true })
}

// 修改微信/支付宝信息
const updateWechatOrAlipay = (params: Receipt.Params.AddOrUpdateContent) => {
    return http.post('/payment-options/payment-method/update', params, { loading: true })
}

export default {
    getReceiptMethod,
    getBankNameList,
    getDefaultReceiptAccount,
    getReceiptList,
    addBankCard,
    addWechatOrAlipay,
    getBankNameByCardNo,
    getBankInfoByCardImage,
    deleteReceipt,
    setIsDefault,
    getDetailInfo,
    updateBankCard,
    updateWechatOrAlipay
}